package gui.main;

import gui.components.HistoryDialog;
import gui.components.MenuBar;
import gui.components.OrderDialog;
import gui.components.ProducerInfoPanel;
import gui.components.WaitTimeDialog;
import gui.graph.controller.GraphController;
import gui.graph.controller.GraphListener;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@SuppressWarnings("serial")
/**
 * Okno dla calego programu
 * @author Witold Muszynski
 *
 */
public class Frame extends JFrame {
	OrderDialog dialog;
	HistoryDialog historyDialog;
	WaitTimeDialog waitTimeDialog;
	ProducerInfoPanel panel;
	MenuBar menuBar;

	
	public Frame() {
		dialog = new OrderDialog(this, false);
		panel = new ProducerInfoPanel();
		menuBar = new MenuBar();
		historyDialog = new HistoryDialog(this, false);
		waitTimeDialog = new WaitTimeDialog(this, false);
		GraphListener listener = new GraphListener(dialog, historyDialog, panel);
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		setLocationByPlatform(true);
		GraphController graphController = (GraphController) context.getBean("graphController");
		graphController.setFrame(this);
		graphController.init(listener);
		add(graphController.getVv());
		menuBar.setNegotiator(graphController.getNegotiator());
		menuBar.setWaitTimeDialog(waitTimeDialog);
		menuBar.setHistoryDialog(historyDialog);
		setJMenuBar(menuBar);
		add(panel, BorderLayout.EAST);
		pack();

	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable(){

			@Override
			public void run() {
				Frame frame = new Frame();
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setVisible(true);
			}
			
		});
		
	}
	
	
	
}
